﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;

/// <summary>
/// Summary description for Xulydulieu
/// </summary>
public class Xulydulieu
{

    public static string ConnectionString
    {
        get
        {
            return ConfigurationManager.ConnectionStrings["COMPUTERConnectionString"].ConnectionString;
        }

        set
        {
            ConfigurationManager.ConnectionStrings["COMPUTERConnectionString"].ConnectionString = value;
        }
    }

    public static SqlConnection Connection()
    {
        SqlConnection con = new SqlConnection(ConnectionString);
        con.Open();
        return con;
    }

    public static DataTable ExecuteQuery(string sqlcommand)
    {
        SqlConnection con = Connection();
        SqlDataAdapter adpter = new SqlDataAdapter(sqlcommand, con);
        DataTable dt = new DataTable();
        adpter.Fill(dt);
        con.Close();
        return dt;
    }

    public static bool ExecuteNonQuery(string sqlcommand)
    {
        SqlConnection con = Connection();
        SqlCommand cmd = new SqlCommand(sqlcommand, con);
        return cmd.ExecuteNonQuery() != 0;
    }

    public static object ExecuteScalar(string sqlcommand)
    {
        SqlConnection con = Connection();
        SqlCommand cmd = new SqlCommand(sqlcommand, con);
        return cmd.ExecuteScalar();
    }
}